VERSION = 0.1.0
COMMIT_ID = $(shell git rev-list -1 HEAD)
TESTS := $(wildcard tests/*.sh)

build:
	@go build -ldflags "-X risc-v/ld/pkg/linker.Version=${VERSION}-${COMMIT_ID}" rvld.go
	@ln -sf rvld ld

# 清除历史构建产物，重新构建
test: build
	@CC="riscv64-linux-gnu-gcc" \
	$(MAKE) $(TESTS)
	@printf "\e[32m Passed all tests\e[0m\n"

$(TESTS):
	@echo 'Testing' $@
	@./$@
	@printf "\e[32m OK\e[0m \n"

clean:
	@go clean
	@rm -rf out/
	@rm -rf linker

docker_build:
	docker build -t rvld .

docker_run:
	@docker run -v ~/code/go/rvld/:/rvld -it -w /rvld --rm rvld:latest
.PHONY: build clean test $(TESTS)